using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class manager_contents_view_content : System.Web.UI.Page
{
    private string id = "";
    string user_present = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        // test user login yet
        user_present = (string)Session["user"];
        if (user_present == null)
        {
            Response.Redirect("../main/login.aspx");
        }

        id = Request["id"];
        if (id == "new")
        {
            btnUpdate.ImageUrl = "../../images/create.gif";
        }
        else
        {
            btnUpdate.ImageUrl = "../../images/update.gif";
            if (Page.IsPostBack == false)
            {
                BindData();
            }
        }

    }

    protected void BindData()
    {
        Contents Content = Contents.get_Content(Convert.ToInt32(id));
        txtDescription.Text = Content.Description;
        fckContentText.Value = Content.ContentText;
        txtName.Text = Content.PageName;
    }

    protected void execute(object sender, EventArgs e)
    {
        if (id == "new")
        {
            try
            {
                Contents.create_Content(fckContentText.Value, txtDescription.Text, true, user_present, txtName.Text);
                Response.Redirect("list_content.aspx");
            }
            catch (Exception ex)
            {
                ClientScript.RegisterStartupScript(GetType(), "Message", "<script language='javascript'>alert('" + ex.Message.ToString().Replace("'", "") + "');</script>");
            }
        }
        else
        {
            try
            {
                Contents.update_Content(Convert.ToInt32(id), fckContentText.Value, txtDescription.Text, true, user_present, txtName.Text);
                Response.Redirect("list_content.aspx");
            }
            catch (Exception ex)
            {
                ClientScript.RegisterStartupScript(GetType(), "Message", "<script language='javascript'>alert('" + ex.Message.ToString().Replace("'", "") + "');</script>");
            }
        }
    }
}
